﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading;
using Model;

namespace Networking
{
    public class ServerController
    {
        Thread listen;
        
        HandleServer handleserver;
        AuktionCollection auktioncollection;
        public ServerController()
        {
            auktioncollection = new AuktionCollection();
            handleserver = new HandleServer(this, auktioncollection);
            listen = new Thread(handleserver.Listen);
            listen.Start();
            Send("vis");
        }

        #region auktion
        public IEnumerator GetAuktioner()
        {
            return auktioncollection.GetAuktioner();
        }

        #endregion



        #region server
        public void Send(string message)
        {
            handleserver.Send(message);
        }

        public void Byd(Int32 auktionsnr, Double pris)
        {
            Send("byd " + auktionsnr + " " + pris);
        }

        public void GetListe()
        {
            Send("vis");
        }

        public void TilmeldAuktion(long auktionsnr)
        {
            Send("tilmeld " + auktionsnr);
        }
        #endregion


        #region exceptions
        public void SocketException(string exception)
        {
        }

        public void IOException(string exception)
        {
        }

        public void GeneralException(string exception)
        {
        }

        public void UnintentionalDisconnect(string exception)
        {
        }

        public void ObjectDisposedException(string exception)
        {
        }

        #endregion
    }
}
